package cn.lutu.domain.repository.impl;

import cn.lutu.dao.mapper.RoutesMapper;
import cn.lutu.domain.repository.RouteRepository;
import cn.lutu.protocol.entity.Route;
import cn.lutu.protocol.entity.Spot;
import cn.lutu.protocol.vo.RouteVO;
import cn.lutu.util.common.PageInfoToPageDataConverter;
import cn.lutu.util.pojo.vo.PageData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Slf4j
@Transactional
public class RoutRepositoryImpl implements RouteRepository {

    @Autowired
    RoutesMapper  routesMapper;


    @Override
    public PageData<RouteVO> selectRouteList(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询酒店列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<RouteVO> list = routesMapper.selectRouteList();
        PageInfo<RouteVO> pageInfo = new PageInfo<>(list);
        PageData<RouteVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }

    @Override
    public RouteVO selectRouteListById(Long id) {
        return routesMapper.selectRouteListById(id);
    }

    @Override
    public List<RouteVO> selectRoute(Long id) {
        return routesMapper.selectRoute(id);
    }

    @Override
    public int addRoute(Route route) {
        log.debug("开始执行【新增路线数据】，参数：{}", route);
        return routesMapper.insert(route);
    }
    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据id删除路线信息】，参数：{}", id);
        return routesMapper.deleteById(id);
    }

    @Override
    public Route selectRouteById(Long id) {
        log.debug("开始执行【根据id查询路线信息】，参数：{}", id);
        return routesMapper.selectById(id);
    }

    @Override
    public int updateRoute(Route route) {
        log.debug("开始执行【修改路线数据】，参数：{}", route);
        return routesMapper.updateById(route);
    }

    @Override
    public RouteVO getRouteById(Long id) {
        log.debug("开始执行【根据id查询路线信息】，参数：{}", id);
        return routesMapper.selectRouteById(id);
    }

    @Override
    public int countByNameAndNotId(Long id, String name) {
        log.debug("开始执行【统计匹配名称查不匹配ID的标签数量】，ID：{}，名称：{}", id, name);
        QueryWrapper<Route> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name).ne("id", id);
        return routesMapper.selectCount(queryWrapper);
    }
//
//    @Override
//    public List<VoteVO> selectVoteById(Long id) {
//        return routesMapper.selectVoteById(id);
//    }

}
